﻿using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;

public partial class BalanceCenter__GoodSalesAddressEdit : PageBase
{
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!this.IsPostBack)
        {
            if (_User.ID == 1)
            {
                Panel1.Visible = true;
                tbUserName.Enabled = false;
                tbTel.Enabled = false;
                tbAddress.Enabled = false;

                lbTitle.Text = "填写快递单号";
            }
            else
            {
                lbTitle.Text = "填写收货地址";
            }

            ReadAction();
            BindData();
        }
    }

    #region Web 窗体设计器生成的代码

    override protected void OnInit(EventArgs e)
    {
        isRequestLogin = true;
        SecondLevelPassword = true;
        RequestLoginPage = "BalanceCenter/_GoodSalesAddressEdit.aspx";

        base.OnInit(e);
    }

    #endregion

    protected void btnOK_Click(object sender, EventArgs e)
    {
        long ID = ShoveEL._Convert.StrToLong(hID.Value, 0);

        if(_User.ID == 1)
        {
            if (tbAddress.Text.Trim() == "")
            {
                ShoveEL._Web.JavaScript.Alert(this.Page, "会员还未填写收货信息，不能发货!");
                return;
            }            

            if (tbOrderNo.Text.Trim() == "")
            {
                ShoveEL._Web.JavaScript.Alert(this.Page, "快递单号不能为空!");
                return;
            }

            int i = DAL.Tables.T_Shipment.Update("[ID]=" + ID, 0, false, "", false, tbAddress.Text.Trim(), true, tbTel.Text.Trim(), true, tbOrderNo.Text.Trim(), true, DateTime.Today, false, true, true, tbRemark.Text.Trim(), false, tbRemark.Text.Trim(), true, DateTime.Today, true);
            if (i >= 0)
            {
                ShoveEL._Web.JavaScript.Alert(this.Page, "填写成功!", "_GoodSalesAddress.aspx");
                return;
            }
        }
        else
        {
            if (tbAddress.Text.Trim() == "")
            {
                ShoveEL._Web.JavaScript.Alert(this.Page, "收货地址不能为空!");
                return;
            }

            int i = DAL.Tables.T_Shipment.Update("[ID]=" + ID, 0, false, "", false, tbAddress.Text.Trim(), true, tbTel.Text.Trim(), true, tbOrderNo.Text.Trim(), true, DateTime.Today, false, false, false, tbRemark.Text.Trim(), true, tbRemark.Text.Trim(), false, DateTime.Today, false);
            if (i >= 0)
            {
                ShoveEL._Web.JavaScript.Alert(this.Page, "填写成功!", "_GoodSalesAddress.aspx");
                return;
            }
        }
    }

    private void ReadAction()
    {
        this.hID.Value = ShoveEL._Web.Utility.GetRequest("id");
    }  

    private void BindData()
    {
        if (this.hID.Value != "")
        {
            long ID = ShoveEL._Convert.StrToLong(hID.Value, -1);
            DataTable dt = null;

            try
            {
                dt = DAL.Tables.T_Shipment.Select("", "[ID]=" + ID, "");

                if (dt == null)
                {
                    PublicFunction.GoError(ErrorNumber.DataReadWrite, "数据读写错误", this.GetType().BaseType.FullName);
                    return;
                }
                
                tbUserName.Text = dt.Rows[0]["UserName"].ToString();
                tbAddress.Text = dt.Rows[0]["Address"].ToString();
                tbTel.Text = dt.Rows[0]["Tel"].ToString();
                tbOrderNo.Text = dt.Rows[0]["OrderNo"].ToString();

                if (_User.ID == 1)
                {
                    tbRemark.Text = dt.Rows[0]["ShopRemark"].ToString(); 
                }
                else
                {
                    tbRemark.Text = dt.Rows[0]["UserRemark"].ToString();
                }
            }
            catch { }

        }
    }
 
}